﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Xml.Serialization;

using Common;

namespace Client
{
    class Client
    {
        public static void Main()
        {

            try
            {
                TcpClient tcpclnt = new TcpClient();
                Console.WriteLine("Connecting.....");

                tcpclnt.Connect("127.0.0.1", 8001);
                // use the ipaddress as in the server program

                Console.WriteLine("Connected");
                Console.Write("Enter the string to be transmitted : ");

                String str = Console.ReadLine();
                PlainText pt = new PlainText(str);
               
                Stream stm = tcpclnt.GetStream();
                var xmlSerializer = new XmlSerializer(typeof(PlainText));

                if (stm.CanWrite)
                {
                    xmlSerializer.Serialize(stm, pt);
                }
                tcpclnt.Close();
            }

            catch (Exception e)
            {
                Console.WriteLine("Error..... " + e.StackTrace);
            }
        }
    }
}
